﻿/// <reference path="../typings/tsd.d.ts" />
/// <reference path="../scripts/autojs/auto.d.ts" />

$(function () {
    $("form").autoForm({
        ajaxurl: "asdasdasd",
        cols: 2,
        fields: [{
            field: "ID",
            type: "prikey"
        }, {
            field: "XMID",
            title: "所属地面工程项目",
            type: "tree",
            span: 2,
            addData: "1.json"
        }, {
            field: "WJMC",
            title: "文件名称",
            type: "string",
            span: 1
        }, {
            field: "SJDW",
            title: "设计单位",
            type: "string",
            span: 1
        }, {
            field: "WCRQ",
            title: "完成日期",
            type: "date",
            span: 1
        }]
    })
    /*DOM
        <input id="fu" type="file" value="" />
        <input id="fu2" type="file" value="" />
    */
    /*JS的用法 */
    $("#fu").autoFileUploader({ url: "/api/SYS/fileupload" });
    $("#fu2").autoFileUploader({ url: "/api/SYS/fileupload2", filter: '.jpg|.txt|.docx', text: '请选择文件' })
        .on("done", function (event, msg) {
            console.log("响应了done事件" + msg);
        })
        .on("canceled", function (event) {
            console.log("响应了cancle事件");
        })
        .on("error", function (event, msg) {
            console.log("响应了error事件" + msg);
        });

    $.auto.setupWS("localhost", 20000);
    $.auto.ajax("/api/tmp/org", {
        data: { dwdm: 1 }
    }).done(function (data) {
        $("#posdiv").screenfull();
    })
    $("#ny").autoDate("ny");
    /* $.ajax("/api/tmp/org", {
         type:'POST',dataType:'json'
     }).done(function (ret) {
         
     });*/
    /*1、添加面板 */
    //$("#layout").tabpanel();
    //$("#layout").tabpanel("add", { id: "a", title: "shena", url: "/home/index" });
    //$("#layout").tabpanel("add", { id: "b", title: "shenb", url: "/home/index" });
    //$("#layout").tabpanel("add", { id: "c", title: "shenc", url: "/home/index" });
    //$("#layout").tabpanel("add", { id: "d", title: "shend", url: "/home/index" });
    //$("#layout").tabpanel("add", { id: "e1", title: "shene", url: "/home/index" });

    /*2\ 表格应用*/
    let data = [];
    for (let i = 1; i <= 100; i++)
        data.push({
            name: "shen" + i,
            age: i,
            address: "address is " + i

        });

    var $tt = $("#tt")
    $("#tt").autoTable({
        data: data,
        header: [
            [{ title: "序号", span: [] },
            { title: "姓名", span: [] },
            { title: "年龄|age", span: [] },
            { title: "住址", span: [] }]
        ],
        headerFields: ["name", "age", "address"],
        header2: [
            [{ title: "序号", span: [1, 2] },
            { title: "31", span: [3, 1] }],
            [
                { title: "姓名", span: [] },
                { title: "年龄|age", span: [] },
                { title: "住址", span: [] }]
        ],
        header2Fields: ["name", "age", "address"],
        isRownumber: true,
        isFooter: true,
        isPageable: false,
        isSaveable: true,
        isScrollable: true,
        saveURL: '/api/sys/export',
        columnsWidths: [50, 60, 100, 100],
        sortFields: ["age"],
        selectMode: AUTO.SelectMode.SINGLE,
        keydataOnRow: ["age"],

        editUrl: "aa",
        editTable: "tjxx_01",
        editKeyFields: ["name"],
        editFields: ["age", "address"],
        editTopHover: true,
        filter: function (row) {
            return row.age % 3 != 0;
        },
    });

    $('#btnN').click(function () {
        $tt.trigger("hide", "name");
        setTimeout(function () {
            //  $tt.trigger("show", "name");
        }, 1000);
    });


    /*行顺序上下移动*/
    $("#btnUp").click(function () {
        //选中当前行
        var $tr = $("#tt").find('.autoselected');
        if ($tr.length == 1 && $tr.prop('rowIndex') > 0) {
            $tr.insertBefore($tr.prev());
        }
    });
    $("#btnDown").click(function () {
        //选中当前行
        var $tr = $("#tt").find('.autoselected');
        if ($tr.length == 1) {
            $tr.insertAfter($tr.next());
        }
    });
    /*t行顺序上下拖动*/
    /*  var isDrag = false;
      var $selTr;  //当前选中行。
      //点击时
      $("#tt").on("mousedown", "tr", function () {
          $selTr = $(this);
          if ($selTr.hasClass("autoheader2")) return;
          //鼠标点击后，当前行加个样式，鼠标变手形。
          $selTr.addClass("auto-drag-row");
          $("#tt").addClass("auto-drag-table");
          isDrag = true;
      });
      //移动时
      $("#tt").on("mousedown", "tr", function () {
          var $tr = $(this);
          if ($tr.hasClass("autoheader2")) return;
          //鼠标点击后，当前行加个样式，鼠标变手形。
          $tr.addClass("auto-drag-row");
          $("#tt").addClass("auto-drag-table");
          isDrag = true;
      });
      */

    /*  $("form").autoForm({
        ajaxurl: 'aaa',
        cols: 2,
        fields: [
            { field: "XMID", type: "prikey" },
            { field: "XMMC", title: "项目名称", type: "string", span: 1 },
            { field: "QKMC", title: "合同区块名称", type: "string", span: 1 },
            { field: "YQTMC", title: "油气田名称", type: "string", span: 1 },
            { field: "XMZT", title: "项目状态", type: "string", span: 1 },
            { field: "YZ", title: "业主", type: "string", span: 1 },
            { field: "CBS", title: "承包商", type: "string", span: 1 },
            { field: "JSGM", title: "建设规模", type: "string", span: 1 },
            { field: "JHZTZE", title: "计划总投资额", type: "number", placeholder: "万元", span: 1 },
            { field: "SJZTZE", title: "实际总投资额", type: "number", placeholder: "万元", span: 1 },
            { field: "JHKGRQ", title: "计划开工日期", type: "date", span: 1 },
            { field: "JHGQ", title: "计划工期", type: "number", placeholder: "天", span: 1 },
            { field: "SJKGRQ", title: "实际开工日期", type: "date", span: 1 },
            { field: "SJGQ", title: "实际工期", type: "number", placeholder: "天", span: 1 }],
        tableName: "ap_ttt",


    });




    $("#ny").autoDate("ny");


    $.auto.setupWS("localhost", 20000);
    var shen = "shenjunjian";
    $("#join").click(function () {
        $.auto.join("fgs", function (data) {
            console.log(this);
            console.log(data);
            console.log(shen);
        });
    });
    $("#leave").click(function () {
        $.auto.leave("fgs");
    });
    $("#broadcast").click(function () {
        $.auto.broadcast("fgs", "aaa");
    });

    /*  $("button").click(function () {
        var t1 = new Date();
        $.auto.ajax("/api/tmp/org", {
            data: { dwdm: 1 }
        }).done(function (data) {
            console.log("socket:" + (new Date().valueOf() - t1.valueOf()));
        }) 
        setTimeout(function () {
            var t2 = new Date();
            $.ajax("/api/tmp/org", {
                data: { dwdm: 1 }, type: 'POST', dataType: 'json'
            }).done(function (data) {
                console.log("ajax:" + (new Date().valueOf() - t2.valueOf()));
            })
        }, 2000);
    });*/
});
